<?php
	include "../functions.php";
	class demo{
		private $data;//查询参数集
		function __call($funcName,$args){
			$db = include "user.db";
			$arr = explode( "_",$funcName);
			if($arr[0]=='user'){
				return $db[$arr[1]];
			}else if(array_key_exists($funcName,current($db))){//p($obj->age("22"));
				//遍历所有学生
				foreach($db as $v){
					if($v[$funcName]==current($args)){
						return $v;
					}
				}
				return null;
			}
		}
		//将所有赋值操作压入$this->data数组中
		public function __set($name,$value){
			$this->data[$name] = $value;
		}
		public function all(){
			$db = include "user.db";
			if(empty($this->data)){
				return $db;
			}else{
				$name = key($this->data);
				$value = current($this->data);
				foreach($db as $u){
					if($u[$name]==$value){
						return $u;
					}
				}
				return null;
			}
		}
		public function __unset($name){
				$db = include "user.db";
				foreach($db as $k=>$u){
					if($u["username"]==$name){
						unset($db[$k]);
					}
				}
				file_put_contents("user.db","<?php \nreturn ".var_export($db,true)."\n?>");
		}
	}
	$obj = new demo;
	// p($obj->user_1());  1
	//p($obj->age("312"));

	// $obj->age=32;
	// p($obj->all());
	unset($obj->wangwu);

?>